<?php

namespace App\Http\Controllers\Task;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class TaskController extends Controller
{
    //任务执行时间
    protected $task_time = 3;
    //脚本执行时间不设置0
    protected $limit_time = 120;
    //继承任务执行时 是否释放1秒等待执行
    protected $is_sleep = false;

    protected function init()
    {
    }

    public function run(Request $request)
    {
        return $this->success('无任务执行');
    }

    public function start_bluk(Request $request)
    {
        $this->init();
        $start = time();
        $i = 0 ;
        set_time_limit($this->limit_time);
        do{
            $retrun = $this->run($request);
            if($this->is_sleep){
                sleep(1);
                $this->is_sleep = false;
            }
            $end = time();
        }while( $end<($start+$this->task_time) );
        return $retrun;
        
    }
}
